﻿using GSPatEditor.Pat;
using GSPatEditor.Simulator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GSPatEditor.UI
{
    partial class AnimationEditor : Form
    {
        public static void RunSimulation(World world, Palette pal)
        {
            var cache = new AnimationImageCache(pal);
            var form = new AnimationEditor()
            {
                ClientSize = new Size(800, 600),
                MaximizeBox = false,
                FormBorderStyle = FormBorderStyle.Fixed3D,
            };
            var imageBox = new PictureBox()
            {
                Left = 0, Top = 0,
                Width = 800, Height = 600,
                Visible = true,
            };
            form.Controls.Add(imageBox);
            imageBox.Paint += delegate(object sender, PaintEventArgs e)
            {
                e.Graphics.Clear(Color.Black);
                world.Render(e.Graphics, cache);
            };

            form.Show();
            world.Update();
            while (form.Visible)
            {
                Application.DoEvents();
                world.Update();
                imageBox.Invalidate(false);
                Thread.Sleep(16);
            }
        }

        public AnimationEditor()
        {
            InitializeComponent();
        }
    }
}
